function  [header,data] = readData(fname,nhead,ncols)

%  open file for input, include error handling
fin = fopen(fname,'r');
if fin < 0
   error(['Could not open ',fname,' for input']);
end

header='';

%  Read and discard header text on line at a time
for i=1:nhead
    buffer = fgetl(fin);
    buf = regexp(buffer,', ','split');
    header = [header buf];
end

data = fscanf(fin,'%f');  %  Load the numerical values into one long vector
nd = length(data);        %  total number of data points
nr = nd/ncols;            %  number of rows; check (next statement) to make sure
if nr ~= round(nd/ncols)
   fprintf(1,'\ndata: nrow = %f\tncol = %d\n',nr,ncols);
   fprintf(1,'number of data points = %d does not equal nrow*ncol\n',nd);
   error('data is not rectangular')
end

data = reshape(data,ncols,nr)'; 

%  end of readColData.m

